package com.b2c.web;

import com.b2c.common.enums.ExceptionEnums;
import com.b2c.common.exception.MrException;
import com.b2c.service.ItemService;
import com.mr.service.pojo.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ItemController
 * @Description: TODO
 * @Author shenyaqi
 * @Date 2020/7/14
 * @Version V1.0
 **/

@RestController
@RequestMapping("item")
public class ItemController {
    @Autowired
    private ItemService itemservice;

    @PostMapping
    public ResponseEntity addItem(Item item){
        if(item.getPrice()==null){

//            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("dddd");
            //抛出异常
//            throw new RuntimeException("价钱不能为空");
           // throw new MrException(ExceptionEnums.PRICE_CANNOT_BE_NULL);
            throw new MrException(ExceptionEnums.PRICE_CANNOT_BE_NULL);
        }
        return  ResponseEntity.status(HttpStatus.BAD_REQUEST).body(itemservice.saveItem(item));
    }
}
